package com.ruoyi.export.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.export.service.impl.ExportServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 通用导出
 */
@RestController
@RequestMapping("/export")
public class ExportController extends BaseController {

    @Autowired
    private ExportServiceImpl exportService;


    /**
     * 通用模板下载
     * 根据前台请求的模板名称
     * @param request
     * @param response
     */
    @GetMapping("/downloadTemplate")
    public void downloadTemplate(HttpServletRequest request, HttpServletResponse response) {
        try {
            String tmplName = request.getParameter("tmplName");
            String fileName = request.getParameter("fileName");
            if(StringUtils.isBlank(tmplName)){
                tmplName = "导入模板.xlsx";
            }
            if(StringUtils.isBlank(fileName)){
                fileName = tmplName;
            }
            exportService.downloadTemplate(tmplName, fileName, request, response);
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }


}
